package com.rbac.controller;

import com.apis.permission.PermissionApis;
import com.common.annotation.Authority;
import com.domain.dto.PageDTO;
import com.domain.dto.permission.AddPermissionDTO;
import com.domain.dto.permission.ModifyPermissionDTO;
import com.domain.dto.permission.PermissionDTO;
import com.domain.query.permission.PermissionQuery;
import com.domain.vo.JsonVO;
import com.rbac.service.IPermissionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "权限控制层")
@RestController
@RequestMapping("permission")
public class PermissionController implements PermissionApis {

    @Autowired
    private IPermissionService permissionService;
    @Override
    @GetMapping("/query-list")
    @Authority("system:permission:list")
    @Operation(summary = "查询权限列表（条件+分页）")
    public JsonVO<PageDTO<PermissionDTO>> queryPermissionList(@Validated @ParameterObject PermissionQuery permissionQuery) {
        PageDTO<PermissionDTO> permissionPage = permissionService.queryPermissionList(permissionQuery);
        return JsonVO.success(permissionPage);
    }

    @Override
    @GetMapping("/query-id")
    @Authority("system:permission:query")
    @Operation(summary = "查询权限数据（单条）")
    public JsonVO<PermissionDTO> queryPermissionByPermissionId(Integer permissionId) {
        return JsonVO.success(permissionService.queryPermissionByPermissionId(permissionId));
    }

    @Override
    @PostMapping("/add")
    @Authority("system:permission:add")
    @Operation(summary = "添加权限")
    public JsonVO<Integer> addPermission(@Validated @ParameterObject AddPermissionDTO addPermissionDTO) {
        return JsonVO.success(permissionService.addPermission(addPermissionDTO));
    }

    @Override
    @PutMapping("/modify")
    @Authority("system:permission:modify")
    @Operation(summary = "修改权限")
    public JsonVO<Integer> modifyPermission(@Validated @ParameterObject ModifyPermissionDTO modifyPermissionDTO) {
        return JsonVO.success(permissionService.modifyPermission(modifyPermissionDTO));
    }

    @Override
    @DeleteMapping("/remove/{permissionIds}")
    @Authority("system:permission:remove")
    @Operation(summary = "删除权限数据（支持批量删除）")
    public JsonVO<Integer> removePermission(@PathVariable List<Integer> permissionIds) {
        return JsonVO.success(permissionService.removePermission(permissionIds));
    }

}

//
//    @GetMapping("/tree")
//    public JsonVO getTreeMenu(@RequestParam("userId") Integer userId){
//        System.out.println("访问成功"+userId);
//        List<Permission> list = permissionService.getTreeMenu(userId);
//        return JsonVO.success(list);
//    }
//
//    @GetMapping("/listAll")
//    public JsonVO getPermissionListAll() {
//        return permissionService.getPermissionListAll();
//    }
//    @GetMapping("/info")
//    public JsonVO getPermission(Integer roleId) {
//        List<Permission> list = permissionService.getUserPermissionByRoleId(roleId);
//        return JsonVO.success(list);
//    }
//    @PutMapping("/updateRolePermission")
//    public JsonVO updateRolePermission(@RequestBody RolePermissionDto rolePermissionDto){
//        System.out.println(rolePermissionDto);
//        return permissionService.updateRolePermission(rolePermissionDto);
////        return null;
//    }